package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itcat.api.mysql.CmsPrefrenceAreaProductRelationApi;
import com.itcat.mapper.CmsPrefrenceAreaProductRelationMapper;
import com.itcat.mysql.pojo.CmsPrefrenceAreaProductRelation;
import com.itcat.mysql.pojo.PmsMemberPrice;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jerry Broker
 * @project_name rainbow-mall
 * @create 2022-04-03 23:59
 */
@DubboService
public class CmsPrefrenceAreaProductRelationApiImpl implements CmsPrefrenceAreaProductRelationApi {

    @Autowired
    private CmsPrefrenceAreaProductRelationMapper cmsPrefrenceAreaProductRelationMapper;


    /**
     * 保存优选专区和商品的关系
     * @param prefrenceAreaProductRelationList
     */
    @Override
    public void saveList(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList) {
        cmsPrefrenceAreaProductRelationMapper.batchInsert(prefrenceAreaProductRelationList);
    }

    /**
     * 通过商品id查找CmsPrefrenceAreaProductRelation
     * @param productId
     * @return
     */
    @Override
    public List<CmsPrefrenceAreaProductRelation> findByProductId(Long productId) {

        LambdaQueryWrapper<CmsPrefrenceAreaProductRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CmsPrefrenceAreaProductRelation::getProductId, productId);
        List<CmsPrefrenceAreaProductRelation> cmsPrefrenceAreaProductRelationList = cmsPrefrenceAreaProductRelationMapper.selectList(queryWrapper);
        return cmsPrefrenceAreaProductRelationList;
    }

    /**
     * 更新优选专区和商品的关系
     * @param prefrenceAreaProductRelationList
     */
    @Override
    public void updateList(List<CmsPrefrenceAreaProductRelation> prefrenceAreaProductRelationList) {
        cmsPrefrenceAreaProductRelationMapper.batchUpdate(prefrenceAreaProductRelationList);
    }

    /**
     * 删除响应商品id的数据
     * @param productId
     */
    @Override
    public void deleteByProductId(Long productId) {
        LambdaQueryWrapper<CmsPrefrenceAreaProductRelation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(productId != null, CmsPrefrenceAreaProductRelation::getProductId, productId);
        cmsPrefrenceAreaProductRelationMapper.delete(queryWrapper);
    }
}
